<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>编辑批次</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <link rel="stylesheet" href="../../static/css/font.css" th:href="@{/css/font.css}">
    <link rel="stylesheet" href="../../static/css/xadmin.css" th:href="@{/css/xadmin.css}">
    <link rel="stylesheet" href="../../static/css/all-member.css" th:href="@{/css/all-member.css}">
</head>

<body>
    <div style="overflow-y:scroll;" id="form-container">
        <form action="" class="layui-form layui-form-pane">
            <div class="layui-form-item" th:if="${trainingBatch}">
                <label class="layui-form-label">培训批次:</label>
                <div class="layui-input-block">
                    <input type="text" name="batchName" th:value="${trainingBatch.batchName}" autocomplete="off"
                        required lay-verify="required" class="layui-input">
                </div>
                <label class="layui-form-label">开始时间:</label>
                <div class="layui-input-block">
                    <input name="startTime" id="startTime" th:value="${#dates.format(trainingBatch.startTime,'yyyy-MM-dd HH:MM:SS')}" type="text" autocomplete="off" required lay-verify="required"
                       class="layui-input">
            </div>
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-block">
                <input name="endTime" id="endTime" type="text" th:value="${#dates.format(trainingBatch.endTime,'yyyy-MM-dd HH:MM:SS')}" autocomplete="off" required lay-verify="required"
                       class="layui-input">
            </div>
            <label class="layui-form-label">容纳人数:</label>
            <div class="layui-input-block">
                <input name="maxNum" id="maxNum" type="text" th:value="${trainingBatch.maxNum}" autocomplete="off" required lay-verify="required"
                       class="layui-input">
            </div>
            <label class="layui-form-label">批次描述:</label>
            <div class="layui-input-block">
                <input name="trainingDescription" id="trainingDescription" th:value="${trainingBatch.trainingDescription}" type="text" autocomplete="off" required
                       lay-verify="required" class="layui-input">
            </div>
            <label class="layui-form-label">批次类型:</label>
                <div class="layui-input-block">
                    <select name="type" id="type">
                        <option value="">请选择批次类型</option>
                        <option value="0" th:selected="${trainingBatch.type} == '0'">正在培训</option>
                                <option value="-1" th:selected="${trainingBatch.type}== '-1'">未开始培训</option>
                    </select>
                </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="float:right;padding-right: 20px">
                <button class="layui-btn" lay-submit lay-filter="formUpdate">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript" src="../../static/lib/layui/layui.js" charset="utf-8"
        th:src="@{/lib/layui/layui.js}"></script>
<script type="text/javascript" src="../../static/js/xadmin.js" th:src="@{/js/xadmin.js}"></script>
<script type="text/javascript" src="../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script th:inline="NONE">
    var batchId = window.location.href.match(/\=(.*)/)[1];
    console.log(batchId);
    $('#form-container').css('height', $(window).height() + 'px');
    layui.use(['form', 'table', 'laydate'], function () {
        var form = layui.form;
        var laydate = layui.laydate;
        form.render();
        laydate.render({
            elem: '#startTime',
            type: "datetime"
        })
        laydate.render({
            elem: '#endTime',
            type: "datetime"
        })

        form.on('submit(formUpdate)', function (data) {
            console.log(JSON.stringify(data.field));
            var data = data.field;
            var newData = data;
            newData.type = JSON.parse(data.type);
            newData.id = batchId;
            $.ajax({
                url: '/v1/training/updateTrainingBatch',
                contentType: 'application/json',
                type: 'POST',
                data: JSON.stringify(newData),
                success: function (res) {
                    console.log("成功了");
                    layer.msg(res.msg);
                    var index = parent.layer.getFrameIndex(window.name);
                    setTimeout(function () {
                        parent.layer.close(index);
                    },2000);
                }, error: function (res) {
                    console.log("失败", res.msg);
                }, complete: function (res) {
                    console.log("完成", res);
                }
            })
        })
    });
</script>
</body>

</html>